package cn.itheima.service.system.impl;

import cn.itheima.dao.MenuRepository;
import cn.itheima.domain.system.Menu;
import cn.itheima.service.system.MenuService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by millions on 2017/7/20.
 */
@Service
@Transactional
public class MenuServiceImpl implements MenuService{

    @Autowired
    private MenuRepository menuRepository;

    @Override
    public List<Menu> findAll() {
        return menuRepository.findAll();
    }

    @Override
    public void save(Menu model) {
        if(model.getParentMenu()!=null && model.getId()==0){
            model.setParentMenu(null);
        }
        menuRepository.save(model);
    }
}
